package cn.iocoder.yudao.module.biz.controller.admin.contract;

import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
import cn.iocoder.yudao.module.biz.dal.dataobject.contract.ContractArchiveDO;
import cn.iocoder.yudao.module.biz.service.contract.ContractArchiveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Component
@Slf4j
public class ContractStatusCheckTask {


    @Resource
    private ContractArchiveService contractArchiveService;

    @Scheduled(cron = "0 0 0 * * ?")
    @TenantJob
    public void changeContractStatus() {
        List<ContractArchiveDO> contractArchiveDOList = contractArchiveService.getExpiredContractArchiveList();
        for (ContractArchiveDO contractArchiveDO : contractArchiveDOList) {
            contractArchiveService.changeStatusToRenew(contractArchiveDO.getId());
        }
        log.info("合同状态检查任务执行完成"+ new Date().toString());
    }

}
